var dashData = false;
Ext.Ajax.timeout = 1800000;
var updateDash = function(orgName) {
    dashData = false;
    Ext.Ajax.request({
        url: 'rest/info/basicInfoByOrgName',
        method: 'GET',
        params: {
            orgName: orgName || 'all'
        },
        success: function(resp) {
            dashData = Ext.JSON.decode(resp.responseText);
        }
    });
};
updateDash();
Ext.application({
    requires: ['Ext.container.Viewport'],
    name: 'cfWeb',
    appFolder: 'cfWeb',
    launch: function() {
        Ext.create('Ext.container.Viewport', {
            layout: 'fit',
            style: 'padding:0px',
            items: [
                {
                    xtype: 'container',
                    layout: 'border',
                    items: [
                        {
                            xtype: 'navView',
                            height: 56,
                            title: '宁波政务云计算中心',
                            region: 'north',
                            menu: [
                                {
                                    id: 'setting',
                                    name: cfWebLang.NavView.setting
                                },
                                {
                                    id: 'message',
                                    name: cfWebLang.NavView.message
                                },
                                {
                                    id: 'accountSetting',
                                    name: cfWebLang.NavView.accountSetting
                                },
                                {
                                    id: 'exit',
                                    name: cfWebLang.NavView.exit
                                }
                            ],
                            cls: 'navView',
                            store: Ext.create('Ext.data.Store', {
                                autoLoad: true,
                                sortOnLoad: true,
                                fields: ['navName', 'navTarget'],
                                data: [
                                    {
                                        navName: '主页',
                                        navTarget: 'index'
                                    },
                                    {
                                        navName: '模板管理',
                                        navTarget: 'templateManage'
                                    },
                                    {
                                        navName: '应用监控',
                                        navTarget: 'appMonitor'
                                    },
                                    {
                                        navName:'应用审批',
                                        navTarget:'appAudit'
                                    }
                                ]
                            })
                        },
                        {
                            xtype: 'mainView',
                            region: 'center',
                            cls: 'mainView'
                        }
                    ]
                }
            ]
        });
    },
    controllers: ['util.NavController',
        'util.MenuController',
        'util.MainController',
        'util.HomeTabController',
        'appManage.AppManageController',
        'dataStorage.DataStorageController',
        'dataAnalyse.DataAnalyseController',
        'appService.AppServiceController',
        'app.AppController',
        'accountSetting.AccountSettingController',
        'log.LogController',
        'appManage.ThresholdController',
        'util.MessageController',
        'accountSetting.ChangePasswdController',
        'accountSetting.QuotaManageController',
        'appAudit.AppAuditController',
        'serviceAudit.ServiceAuditController'
    ]
});

Ext.Ajax.on('requestexception', function(conn, response, options) {
    if (response.status == '401') {
        Ext.Msg.show({
            title: cfWebLang.Util.Tip,
            id: 'firstWin',
            msg: cfWebLang.Main.SessionOverdue,
            width: 250,
            buttons: Ext.MessageBox.OK,
            fn: function() {
                parent.location.href = './login.html';
            },
            cls: 'overtimeWin'
        });
        //Ext.WindowManager.bringToFront ('firstWin');
        /* Ext.Msg.alert(cfWebLang.Util.Tip,cfWebLang.Main.SessionOverdue, function(){
             parent.location.href = '/cfWeb/login.html';
         }); */
        return;
    }

    if (response.timedout) {
        Ext.Msg.alert(cfWebLang.Util.Tip, cfWebLang.global.timeout);
        return;
    }

    var error = Ext.JSON.decode(response.responseText);
    if (error.data != null && error.data.source == 1) {
        Ext.MessageBox.alert(cfWebLang.ErrorSource.cloudfoundry, error.data.message);
    } else {
        Ext.MessageBox.alert(cfWebLang.ErrorSource.app, cfWebLang.Error.SystemError);
    }
});
